﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace gpuimp.core
{
    public class ToolManager
    {
        static int activeTool;
        static List<Tool> toolList;

        /// <summary>
        /// creates a new tool manager
        /// </summary>
        public ToolManager()
        {
            toolList = new List<Tool>() ;       
        }

        public static void SetTool(ToolType type)
        {
            for (int i = 0; i < toolList.Count; i++)
            {
                if (toolList[i].Type == type)
                {
                    activeTool = i;
                    return;
                }
            }
            activeTool = -1;
        }

        public static Tool ActiveTool
        {
            get 
            {
                if (toolList != null)
                {
                    if(activeTool >= 0 && activeTool < toolList.Count)
                        return toolList[activeTool];
                }
                return null;
            }
        }

        /// <summary>
        /// allows the user to add tools to the tool list.  Used when custom tools are made
        /// </summary>
        /// <param name="tool"></param>
        public static void addTool(Tool tool)
        {
            toolList.Add(tool);
        }

        public static void ReloadShaders()
        {
            foreach (Tool t in toolList)
                t.setupShader();
        }

        /// <summary>
        /// delete a tool from the tool list
        /// </summary>
        /// <param name="toolId"></param>
        void deleteTool(int toolId)
        {
            for(int count = 0; count <= toolList.Count(); count++)
            {
                if(toolList.ElementAt<Tool>(count).getID() == toolId)
                {
                    toolList.RemoveAt(count);
                }
                count++;
            }
        }

        /// <summary>
        /// save the current tool set
        /// </summary>
        void saveTools()
        {

        }

        /// <summary>
        /// select which tool is active
        /// </summary>
        /// <param name="toolId"></param>
        void setActiveTool(int toolId)
        {
            activeTool = toolId;
        }

        public static List<Tool> getList()
        {
            return(toolList);
        }
    }
}
